﻿using CID.Domain.Infrastructure;
using CID.Tests.Support;
using NUnit.Framework;
using Rhino.Mocks;

namespace CID.Domain.Tests.Infrastructure
{
    [TestFixture]
    class PackageTypeTests : BaseFunctionalTests
    {
        private const string Name = "Package Type Name";
        private const string Description = "Package Type Description";
        private PackageType packageType;

        public override void SetUp()
        {
            base.SetUp();
            packageType = new PackageType(Name, Description);
        }

        #region Constructor
        [Test]
        public void CreateNewPackageType()
        {
            var packageType = new PackageType(Name, Description);

            Assert.AreEqual(Name, packageType.Name);
            Assert.AreEqual(Description, packageType.Description);
            Assert.IsTrue(packageType.Enabled);
            CollectionAssert.IsEmpty(packageType.Packages);
        }
        #endregion

        #region CreatePackage
        [Test]
        public void CreatePackage_NonActivePackage_ShouldSucceed() 
        {
            var content = new byte[] { 1, 2, 3 };
            var comment = "This is the package";
            var version = Development.StubsBuilder.BuildVersionStub();

            var package = packageType.CreatePackage(version, content, comment, false);

            Assert.IsInstanceOf<Package>(package);
            Assert.AreEqual(packageType, package.Type);
            Assert.AreEqual(version, package.Version);
            Assert.AreEqual(content, package.Content);
            Assert.AreEqual(comment, package.Comment);
            CollectionAssert.Contains(packageType.Packages, package);
            version.AssertWasCalled(x => x.AddPackage(package));
            version.AssertWasNotCalled(x => x.SetActivePackage(package));
        }

        [Test]
        public void CreatePackage_ActivePackage_ShouldSucceed()
        {
            var content = new byte[] { 1, 2, 3 };
            var comment = "This is the package";
            var version = Development.StubsBuilder.BuildVersionStub();

            var package = packageType.CreatePackage(version, content, comment, true);

            Assert.IsInstanceOf<Package>(package);
            Assert.AreEqual(packageType, package.Type);
            Assert.AreEqual(version, package.Version);
            Assert.AreEqual(content, package.Content);
            Assert.AreEqual(comment, package.Comment);
            CollectionAssert.Contains(packageType.Packages, package);
            version.AssertWasCalled(x => x.AddPackage(package));
            version.AssertWasCalled(x => x.SetActivePackage(package));
        }
        #endregion
    }
}
